import 'package:amap_flutter_map/amap_flutter_map.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:maps_launcher/maps_launcher.dart';
import 'package:package_info/package_info.dart';
import 'package:yp/Xwidgets/index.dart';
import 'package:amap_flutter_base/amap_flutter_base.dart'
    show AMapApiKey, AMapPrivacyStatement, LatLng;
import 'package:amap_flutter_location/amap_flutter_location.dart';
import 'package:yp/config/config.dart';
import 'package:yp/helper.dart';
import 'package:yp/pages/mall_app/hall_map/logic.dart';
import 'package:yp/pages/mall_app/hall_map/state.dart';

class HallMapPage extends StatefulWidget {
  const HallMapPage({Key key}) : super(key: key);

  @override
  _HallMapPageState createState() => _HallMapPageState();
}

class _HallMapPageState extends State<HallMapPage> {
  final logic = Get.put(HallMapLogic());
  final HallMapState state = Get.find<HallMapLogic>().state;

  static final AMapApiKey amapApiKeys =
      AMapApiKey(androidKey: Config.AMap_andriod, iosKey: Config.AMap_ios_get);

  CameraPosition _kInitialPosition;
  Set<Marker> markers = {};
  AMapWidget map;

  @override
  void initState() {
    super.initState();
    markers.add(Marker(position: LatLng(state.lat, state.lng)));
    _kInitialPosition = CameraPosition(
      target: LatLng(state.lat, state.lng),
      zoom: 16.0,
    );
    map = AMapWidget(
     privacyStatement: AMapPrivacyStatement(hasContains:true,  hasShow:true,   hasAgree :true  ) ,
        initialCameraPosition: _kInitialPosition,
        apiKey: amapApiKeys,
        markers: markers,
        minMaxZoomPreference: MinMaxZoomPreference(1, 100),
        onMapCreated: (ctrl) {
          logic.onMapCreated(ctrl);
        });
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: YPXNavigationBar('位置信息'),
      body: ConstrainedBox(
        constraints: BoxConstraints.expand(),
        child: Stack(
          alignment: Alignment.center,
          children: [
            Container(
              height: MediaQuery.of(context).size.height,
              width: MediaQuery.of(context).size.width,
              child: map,
            ),
            Positioned(
                right: 10,
                bottom: 15,
                child: Container(
                  alignment: Alignment.centerLeft,
                  child: Column(
                      mainAxisAlignment: MainAxisAlignment.start,
                      children: state.approvalNumberWidget),
                ))
          ],
        ),
      ),
      bottomNavigationBar: Container(
        height: setWidth(150) + Get.bottomBarHeight,
        color: Colors.white,
        width: Get.width,
        padding:
            EdgeInsets.fromLTRB(setWidth(30), 0, setWidth(30), setWidth(30)),
        child:
            Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
          Text(state.data['sub_unit_name'],
              style: TextStyle(
                color: Color(0xff222222),
                fontSize: setWidth(32),
              )),
          IconButton(
            onPressed: () {
              MapsLauncher.launchCoordinates(
                  state.lat, state.lng, state.data['adr']);
            },
            icon: Image.asset(
              'assets/images/navigation_image.png',
              width: setWidth(50),
              height: setWidth(50),
              fit: BoxFit.cover,
            ),
          )
        ]),
      ),
    );
  }
}
